package com.ruoyi.web.controller.zhishiku;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.vo.FileRefGrantVO;
import com.ruoyi.common.core.query.FileRefListQuery;
import com.ruoyi.system.service.FileRefService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@AllArgsConstructor
@RequestMapping("/zhishiku/fileRef")
@ApiOperation("")
public class FileRefController extends BaseController{

    @Resource
    private FileRefService fileRefService;

    /**
     * 分页查询权限列表
     */
    /**
     * {
     *   "page": 1,
     *   "pageSize": 10,
     *   "type": 0, // 用户
     *   "permission": 0, // 新建文件夹
     *   "search": "张", // 模糊搜索关键字
     *   "isAssigned": false // 未授权
     * }
     *
     * {
     *   "list": [
     *     {
     *       "id": 1,
     *       "name": "张三"
     *     },
     *     {
     *       "id": 3,
     *       "name": "张伟"
     *     }
     *   ],
     *   "total": 15, // 总共有 15 个未授权的用户
     *   "page": 1,
     *   "pageSize": 10
     * }
     */
    @ApiOperation("分页查询权限列表")
    @PostMapping("/list")
    public Map list(@RequestBody FileRefListQuery query) {
        return  fileRefService.list(query);
    }


    /**
     * 授权
     * target: this.selectedType, // 对象类型
     *         per_type: this.selectedPermission, // 权限类型
     *         assignedList: this.assignedList, // 已授权的列表
     */
    @ApiOperation("授权")
    @PostMapping("/grant")
    public AjaxResult grant(@RequestBody FileRefGrantVO vo) {
        return AjaxResult.success(fileRefService.grant(vo));
    }


}
